<template>
    <el-container>
        <el-container class="is-vertical">
            <div class="panel-search-box">
                <div class="panel-search">
                    <el-select v-model="search.action" placeholder="操作类型" clearable filterable >
                        <el-option label="新增" value="create"></el-option>
                        <el-option label="编辑" value="update"></el-option>
                        <el-option label="删除" value="delete"></el-option>
					</el-select>
                    <el-input v-model="search.decription" placeholder="描述" clearable  class="w165"></el-input>
                    <el-date-picker v-model="search.createdAt" type="datetimerange" value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss"
							range-separator="至" start-placeholder="操作开始时间" end-placeholder="操作结束时间" class="sDateSelect" style="margin-left:10px;"
						></el-date-picker>
                    <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
                </div>
            </div>
            <el-main class="nopadding">
                <scTable ref="table" :params="search" :apiObj="$API.operationLog.list" stripe remoteSort remoteFilter>
					<el-table-column align="left" label="ID" prop="id" width="100px"></el-table-column>
                    <el-table-column align="center" label="操作时间" prop="createdAt" width="150px"></el-table-column>
                    <el-table-column align="center" label="操作人" prop="operator" width="120px"></el-table-column>
                    <el-table-column align="center" label="操作类型" prop="action" width="120px">
                        <template #default="scope">
                            {{ scope.row.action ? scope.row.action.name : '' }}
                        </template>
                    </el-table-column>
                    <el-table-column align="center" label="描述" prop="decription"></el-table-column>
                    <el-table-column label="操作" fixed="right" align="center" width="150">
                        <template #default="scope">
                            <el-button type="text" size="small" v-if="scope.row.action.value != 'delete'" @click="table_show(scope.row, scope.$index)">查看</el-button>
							<el-divider direction="vertical" v-if="scope.row.action.value != 'delete' &&permissions.delete"></el-divider>
                            <el-popconfirm v-if="permissions.delete" :title="`确认是否删除?`" @confirm="table_del(scope.row)">
                                <template #reference>
                                    <el-button type="text" size="small">删除</el-button>
                                </template>
                            </el-popconfirm>
                        </template>
                    </el-table-column>
                </scTable>
            </el-main>

        </el-container>
    </el-container>

    <detail v-if="dialog.detail" ref="detailDialog"></detail>
</template>

<script>
import { in_array } from '@/utils/index.js'
import { rolePermission } from '@/utils/permission'
import detail from './detail.vue'
export default {
	components: {
		detail
	},
	props: {
	},
	data() {
		return {
			in_array,
			dialog: {
				detail: false
			},
			search: {
				title: null,
				status: null
			},
			permissions: {
                // delete: rolePermission('system-operations-delete'),
                delete: true,
			}
		}
	},
	mounted() {
		
	},
	methods: {
		//查看
        async table_show(row) {
            this.dialog.detail = true
            this.$nextTick(() => {
                this.$refs.detailDialog.open().setData(row)
            })
        },
		// 搜索
		upsearch(){
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSuccess(){
			this.$refs.table.refresh()
		},
		//删除
        async table_del(row) {
            await this.$API.operationLogs.action.delete({ id: row.id }).then(() => {
                this.$refs.table.refresh()
                this.$notify.success("删除成功")
            });
        },
	}
}
</script>

<style scoped>
.position{display: flex;align-items: center;}
.position-item{margin-right: 5px;}
.el-tag + .el-tag{margin-left: 0;margin-top: 5px;}
.position-item:last-child{margin-right: 0;}
.number-data{border-bottom: none !important;}

</style>
